<?php
namespace app\common\component\user_wallet_silver;

use think\Session;
use app\common\component\user\UserModel;

class UserWalletSilverService {
	public function createV01($data) {
		$userWalletSilverModel = new UserWalletSilverModel($data);

    	if($userWalletSilverModel -> save()) {
    		return [
    			'code' => 0,
    			'message' => '银豆钱包创建成功',
    			'data' => [
    				'user_wallet_silver' => $userWalletSilverModel
    			]
    		];
    	}

    	return [
			'code' => -1,
			'message' => '银豆钱包创建失败'
		];
	}

	public function createLogV01($from_user_id, $type, $status) {
		$data = [];

		$getUser = UserModel::get(['user_id' => $from_user_id]);

		if($getUser -> promotion_id > 0) {
			$data['user_id'] = $getUser -> promotion_id;
			$data['from_user_id'] = $from_user_id;
			$data['type'] = $type;
			$data['status'] = $status;
			$data['price'] = getParam('WALLET_SILVER_PRICE');
			$data['interest'] = 0;
			$data['start_time'] = time();
			$data['end_time'] = $data['start_time'] + getParam('WALLET_SILVER_INTEREST_DAYS') * 24 * 60 * 60;

			return $this -> createV01($data);
		}

		return [
			'code' => 0,
			'message' => '无推荐人'
		];
	}
}
?>